

. .\Lib.Imaging.ps1


Set-PSDebug -Strict

Function Out-ImageFormat
{
	param
	(
		  [System.Drawing.Image]	$Image
		, [string]					$Description
	)
	[string] $out = $Description
	$out = $out.PadRight( 40 )
	$out += "$($Image.Width) x $($Image.Height)"
	$out += "`tAspect = $( Calculate-AspectRatio $Image.Width $Image.Height )"
	return $out
}


[psobject]	$I = $null
[psobject]	$I2 = $null

"`n--- Load an image from file ---"
$I = Get-Image "c:\windows\zapotec.bmp"
Out-ImageFormat $I "image from file"

"`n--- Create a test image ---"
$I = Create-Image 800 600
Out-ImageFormat $I "created image"

"`n--- Resize test image ---"
Out-ImageFormat $I "Original Image"

$I2 = Size-Image $I -Width 100
Out-ImageFormat $I2 "Width 100  Height   0  nostretch"

$I2 = Size-Image $I -Height 100
Out-ImageFormat $I2 "Width   0  Height 100  nostretch"

$I2 = Size-Image $I 100 100
Out-ImageFormat $I2 "Width 100  Height 100  nostretch"

$I2 = Size-Image $I 100 200
Out-ImageFormat $I2 "Width 100  Height 200  nostretch"

$I2 = Size-Image $I 200 100
Out-ImageFormat $I2 "Width 200  Height 100  nostretch"

$I2 = Size-Image $I 100 100 $true
Out-ImageFormat $I2 "Width 100  Height 100  stretch"

"`n--- Create and save test images ---"
[byte[]] $Bytes = $null

$I = Create-Image 800 600
$Bytes = Serialize-Image -Image $I -Format [System.Drawing.Imaging.ImageFormat]::Bmp
Set-Content -Path "..\test\test.bmp" -Value $Bytes -Encoding byte
"Image saved: test.bmp"

$I = Create-Image 800 600
$Bytes = Serialize-Image -Image $I -Format [System.Drawing.Imaging.ImageFormat]::Png
Set-Content -Path "..\test\test.png" -Value $Bytes -Encoding byte
"Image saved: test.png"
